package com.project.interceptor;

import com.project.bean.UserBean;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 顾客拦截器
 */
public class CustomInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从session中取出登陆用户
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        if(user != null && "顾客".equals(user.getGrade())){
            return true;
        }
        request.getRequestDispatcher("/login.html?errorInfo=noCustom")
                .forward(request,response);
        return false;
    }
}
